﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IOBusiness;
using System.Data;
using System.Text;

namespace Indochinaodyssey.UserControl.NavigatorMenu
{
    public partial class TopMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblTopMenu.Text = TopMenuCountry();  
            }
        }

        private string TopMenuCountry() {
            string sqlQuocGia = "Select ID,TenQuocGia from tblQuocGia";
            clsBSDungChung bs = new clsBSDungChung();
            DataTable tbCountry = new DataTable();
            tbCountry = bs.GetDataTableSQL(sqlQuocGia, "QuocGia");
            StringBuilder menu = new StringBuilder();
           for (int i = 0; i < tbCountry.Rows.Count; i++)
			{
                menu.Append("<li><a href=\"?country=" + tbCountry.Rows[i][0].ToString() + "\">" + tbCountry.Rows[i][1].ToString() + "</a>");
                menu.Append(TopMenuCategory(tbCountry.Rows[i][0].ToString()));
                menu.Append("</li>");
            }
            
            return menu.ToString();
        }
        private string TopMenuCategory(string countryID) {
            string sql = "SELECT t.TenDanhMuc, t.ID FROM dbo.tblDanhMuc t  where t.ID in(Select l.maDanhmuc from tblTheLoai l where l.maquocgia="+countryID+" group by l.MaDanhMuc)";
            clsBSDungChung bs = new clsBSDungChung();
            DataTable tbCat = new DataTable();
            tbCat = bs.GetDataTableSQL(sql, "Cate");
            StringBuilder menu = new StringBuilder();
            if (tbCat.Rows.Count>0)
            {
                menu.Append("<span>");
            }
            
            for (int i = 0; i < tbCat.Rows.Count; i++)
            {
                if (Convert.ToInt32(tbCat.Rows[i][1].ToString())!=1)
                menu.Append("<a href=\"/Tour.aspx?country="+countryID+"&cateid=" + tbCat.Rows[i][1].ToString() + "\">" + tbCat.Rows[i][0].ToString() + "</a>");
            }
            if (tbCat.Rows.Count > 0)
            {
                menu.Append("</span>");
            }
            return menu.ToString();
        }
    }
}